﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: V_CrmCommisionExtend.cs
// 作 者：代码自动生成
// 日 期：2013/6/14 9:43:45
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
	/// <summary>
    /// 
    /// </summary>
	[Serializable]
    [Table(Name="V_CrmCommisionExtend")]
    [ZX.DBModule.Table("V_CrmCommisionExtend","ID")]
	public class V_CrmCommisionExtend: ZX.DBModule.BaseEntity
	{
        #region Business Methods 业务方法
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > IDProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }
        
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > OrderIdProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("OrderId"));
        [Column]
        public Guid OrderId
        {
            get { return GetProperty(OrderIdProperty); }
            set { SetProperty(OrderIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > OrderProductIdProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("OrderProductId"));
        [Column]
        public Guid OrderProductId
        {
            get { return GetProperty(OrderProductIdProperty); }
            set { SetProperty(OrderProductIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > AttachDateProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("AttachDate"));
        [Column]
        public DateTime AttachDate
        {
            get { return GetProperty(AttachDateProperty); }
            set { SetProperty(AttachDateProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > PayMoneyTotalProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< decimal >("PayMoneyTotal"));
        [Column]
        public decimal PayMoneyTotal
        {
            get { return GetProperty(PayMoneyTotalProperty); }
            set { SetProperty(PayMoneyTotalProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > CommisionPostProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("CommisionPost"));
        [Column]
        public Guid CommisionPost
        {
            get { return GetProperty(CommisionPostProperty); }
            set { SetProperty(CommisionPostProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > CommisionMoneyProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< decimal >("CommisionMoney"));
        [Column]
        public decimal CommisionMoney
        {
            get { return GetProperty(CommisionMoneyProperty); }
            set { SetProperty(CommisionMoneyProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > CommisionScaleProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< decimal >("CommisionScale"));
        [Column]
        public decimal CommisionScale
        {
            get { return GetProperty(CommisionScaleProperty); }
            set { SetProperty(CommisionScaleProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > AdduserProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("Adduser"));
        [Column]
        public Guid Adduser
        {
            get { return GetProperty(AdduserProperty); }
            set { SetProperty(AdduserProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > CheckUserProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("CheckUser"));
        [Column]
        public Guid CheckUser
        {
            get { return GetProperty(CheckUserProperty); }
            set { SetProperty(CheckUserProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > CheckTimeProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("CheckTime"));
        [Column]
        public DateTime CheckTime
        {
            get { return GetProperty(CheckTimeProperty); }
            set { SetProperty(CheckTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > CommisionUserProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("CommisionUser"));
        [Column]
        public Guid CommisionUser
        {
            get { return GetProperty(CommisionUserProperty); }
            set { SetProperty(CommisionUserProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > CommisionTimeProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("CommisionTime"));
        [Column]
        public DateTime CommisionTime
        {
            get { return GetProperty(CommisionTimeProperty); }
            set { SetProperty(CommisionTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > ModifyUserProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("ModifyUser"));
        [Column]
        public Guid ModifyUser
        {
            get { return GetProperty(ModifyUserProperty); }
            set { SetProperty(ModifyUserProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > ModifyTimeProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("ModifyTime"));
        [Column]
        public string ModifyTime
        {
            get { return GetProperty(ModifyTimeProperty); }
            set { SetProperty(ModifyTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > SureUserProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("SureUser"));
        [Column]
        public Guid SureUser
        {
            get { return GetProperty(SureUserProperty); }
            set { SetProperty(SureUserProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > SureTimeProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("SureTime"));
        [Column]
        public DateTime SureTime
        {
            get { return GetProperty(SureTimeProperty); }
            set { SetProperty(SureTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > addusercodeProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("addusercode"));
        [Column]
        public string addusercode
        {
            get { return GetProperty(addusercodeProperty); }
            set { SetProperty(addusercodeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > adduserCnameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("adduserCname"));
        [Column]
        public string adduserCname
        {
            get { return GetProperty(adduserCnameProperty); }
            set { SetProperty(adduserCnameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > adduserPostProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("adduserPost"));
        [Column]
        public string adduserPost
        {
            get { return GetProperty(adduserPostProperty); }
            set { SetProperty(adduserPostProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > CheckCnameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("CheckCname"));
        [Column]
        public string CheckCname
        {
            get { return GetProperty(CheckCnameProperty); }
            set { SetProperty(CheckCnameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > CommisionCnameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("CommisionCname"));
        [Column]
        public string CommisionCname
        {
            get { return GetProperty(CommisionCnameProperty); }
            set { SetProperty(CommisionCnameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > SureNameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("SureName"));
        [Column]
        public string SureName
        {
            get { return GetProperty(SureNameProperty); }
            set { SetProperty(SureNameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > OrderDeptIDProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("OrderDeptID"));
        [Column]
        public Guid OrderDeptID
        {
            get { return GetProperty(OrderDeptIDProperty); }
            set { SetProperty(OrderDeptIDProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > OrderDeptNameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("OrderDeptName"));
        [Column]
        public string OrderDeptName
        {
            get { return GetProperty(OrderDeptNameProperty); }
            set { SetProperty(OrderDeptNameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > CustomerNameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("CustomerName"));
        [Column]
        public string CustomerName
        {
            get { return GetProperty(CustomerNameProperty); }
            set { SetProperty(CustomerNameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > FactPayDateProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("FactPayDate"));
        [Column]
        public DateTime FactPayDate
        {
            get { return GetProperty(FactPayDateProperty); }
            set { SetProperty(FactPayDateProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > LectortimeProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("Lectortime"));
        [Column]
        public DateTime Lectortime
        {
            get { return GetProperty(LectortimeProperty); }
            set { SetProperty(LectortimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > AddCustomerAddProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< DateTime >("AddCustomerAdd"));
        [Column]
        public DateTime AddCustomerAdd
        {
            get { return GetProperty(AddCustomerAddProperty); }
            set { SetProperty(AddCustomerAddProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > ProductNameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("ProductName"));
        [Column]
        public string ProductName
        {
            get { return GetProperty(ProductNameProperty); }
            set { SetProperty(ProductNameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< int > SystemNameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< int >("SystemName"));
        [Column]
        public int SystemName
        {
            get { return GetProperty(SystemNameProperty); }
            set { SetProperty(SystemNameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< int > BargainNumProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< int >("BargainNum"));
        [Column]
        public int BargainNum
        {
            get { return GetProperty(BargainNumProperty); }
            set { SetProperty(BargainNumProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > TotalMoneyProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< decimal >("TotalMoney"));
        [Column]
        public decimal TotalMoney
        {
            get { return GetProperty(TotalMoneyProperty); }
            set { SetProperty(TotalMoneyProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > CommisionRoleNameProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< string >("CommisionRoleName"));
        [Column]
        public string CommisionRoleName
        {
            get { return GetProperty(CommisionRoleNameProperty); }
            set { SetProperty(CommisionRoleNameProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< int > PayMoneyTimeSpanProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< int >("PayMoneyTimeSpan"));
        [Column]
        public int PayMoneyTimeSpan
        {
            get { return GetProperty(PayMoneyTimeSpanProperty); }
            set { SetProperty(PayMoneyTimeSpanProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > ProductidProperty = RegisterProperty(typeof(V_CrmCommisionExtend),new PropertyInfo< Guid >("Productid"));
        [Column]
        public Guid Productid
        {
            get { return GetProperty(ProductidProperty); }
            set { SetProperty(ProductidProperty, value); }
        }
        #endregion
        
        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "ModifyTime");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ModifyTime", 10));
            ValidationRules.AddRule(CommonRules.StringRequired, "addusercode");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("addusercode", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "adduserCname");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("adduserCname", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "adduserPost");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("adduserPost", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "CheckCname");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CheckCname", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "CommisionCname");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CommisionCname", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "SureName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("SureName", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "OrderDeptName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("OrderDeptName", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "CustomerName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CustomerName", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "ProductName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ProductName", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "CommisionRoleName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CommisionRoleName", 50));
            //base.AddBusinessRules();
        }
        #endregion
        
        #region Factory Methods 工厂方法

        public V_CrmCommisionExtend(){}

        public static V_CrmCommisionExtend New()
        {
            return DataPortal.Create< V_CrmCommisionExtend>();
        }
        public static V_CrmCommisionExtend Get(Guid ID)
        {
            return DataPortal.Fetch< V_CrmCommisionExtend>(new SingleLazyCriteria< V_CrmCommisionExtend, Guid>(ID, false));
        }
        public static void Delete(Guid ID )
        {
            DataPortal.Delete(ID);
        }
        
        #endregion
        
        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
             using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                
                var data = db.Select< V_CrmCommisionExtend>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(OrderIdProperty, data.OrderId);
                LoadProperty(OrderProductIdProperty, data.OrderProductId);
                LoadProperty(AttachDateProperty, data.AttachDate);
                LoadProperty(PayMoneyTotalProperty, data.PayMoneyTotal);
                LoadProperty(CommisionPostProperty, data.CommisionPost);
                LoadProperty(CommisionMoneyProperty, data.CommisionMoney);
                LoadProperty(CommisionScaleProperty, data.CommisionScale);
                LoadProperty(AdduserProperty, data.Adduser);
                LoadProperty(CheckUserProperty, data.CheckUser);
                LoadProperty(CheckTimeProperty, data.CheckTime);
                LoadProperty(CommisionUserProperty, data.CommisionUser);
                LoadProperty(CommisionTimeProperty, data.CommisionTime);
                LoadProperty(ModifyUserProperty, data.ModifyUser);
                LoadProperty(ModifyTimeProperty, data.ModifyTime);
                LoadProperty(SureUserProperty, data.SureUser);
                LoadProperty(SureTimeProperty, data.SureTime);
                LoadProperty(addusercodeProperty, data.addusercode);
                LoadProperty(adduserCnameProperty, data.adduserCname);
                LoadProperty(adduserPostProperty, data.adduserPost);
                LoadProperty(CheckCnameProperty, data.CheckCname);
                LoadProperty(CommisionCnameProperty, data.CommisionCname);
                LoadProperty(SureNameProperty, data.SureName);
                LoadProperty(OrderDeptIDProperty, data.OrderDeptID);
                LoadProperty(OrderDeptNameProperty, data.OrderDeptName);
                LoadProperty(CustomerNameProperty, data.CustomerName);
                LoadProperty(FactPayDateProperty, data.FactPayDate);
                LoadProperty(LectortimeProperty, data.Lectortime);
                LoadProperty(AddCustomerAddProperty, data.AddCustomerAdd);
                LoadProperty(ProductNameProperty, data.ProductName);
                LoadProperty(SystemNameProperty, data.SystemName);
                LoadProperty(BargainNumProperty, data.BargainNum);
                LoadProperty(TotalMoneyProperty, data.TotalMoney);
                LoadProperty(CommisionRoleNameProperty, data.CommisionRoleName);
                LoadProperty(PayMoneyTimeSpanProperty, data.PayMoneyTimeSpan);
                LoadProperty(ProductidProperty, data.Productid);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion
	}
}

